<template>
	<view class="vehicle">
		<u-navbar title="收货地管理" title-color="#333" back-icon-color="#333"></u-navbar>
		<view class="vehicle-bottom" style="margin-bottom: 140rpx;">

			<!-- 内容 -->
			<view class="shdList">
				<view class="vehicle-content-box" v-if="vehicleArrList.length != 0" v-for="(item, index) of vehicleArrList"
					:key="index" @click="xhdxzFun(item)">
					<view class="vehicle-content vehicle-car-zdy">
						<!-- 车牌号 -->
						<view>
							<view class="vehicle-car-details vehicle-carNumber" style="display: flex; justify-content: space-between;"
								ref="carNumbers">
								<view class="" style="width: 73%;">
									<view>
										<text class="xzxhdz" v-if="item.CHECKED == 'TRUE'">✔</text> 收货地：<text>{{ item.ORMTB404CA00 }}</text>
									</view>
								</view>
								<view class="" @click.stop="getopsxinxi(item)" style="color: #0099ff;">
									<text class="" ref='modify'>查看位置</text>
								</view>
							</view>
							<view class="vehicle-car-details">
								<view>详细地址：<text>{{ item.ORMTB404CA05 }}</text> </view>
							</view>
						</view>
						<view class="">
							<view class="vehicle-button-box" style="padding-top: 20rpx; padding-bottom: 0;">
								<view class="vehicle-add vehicle-button-margin" @click.stop="modify(item)"
									style="background: rgba(229, 191, 0, 1);">
									<text class="vehicle-add-button" ref='modify'>修改</text>
								</view>
								<view class="vehicle-add" @click.stop="prohibit(item)" style="background: rgba(255, 76, 76, 1);">
									<text class="vehicle-add-button">删除</text>
								</view>
							</view>
						</view>

					</view>
				</view>
			</view>
			<view class="sendorder-loadmore">
				<u-loadmore v-if="vehicleArrList.length != 0" :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
			<!-- 缺醒页 -->
			<view class="zanWSJ" v-if="vehicleArrList.length == 0">
				<image :src="getStaticFilePath('/QXY/noData.png')" alt=""></image>
			</view>
			<u-modal v-model="vehicleLoginShow" :content="vehicleContent" :show-cancel-button="true"
				@confirm="vehicleConfirm"></u-modal>
		</view>
		<view class="xjshd">
			<view class="" style="margin: 0 auto;">
				<u-button style="font-size: 32rpx;" type="error" @click="addCar" shape="circle" size="default">新建收货地址</u-button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
import {
	checkOpenGPSServiceByAndroid
} from '../../util/map.js';
export default {
	data() {
		return {
			userinfo: JSON.parse(uni.getStorageSync('userinfo')),
			status: 'loading',
			iconType: 'flower',
			loadText: {
				loadmore: '轻轻上拉',
				loading: '努力加载中',
				nomore: '实在没有了'
			},
			countpage: 1,
			page: 1,
			vehicleArrList: [],
			vehicleLoginShow: false,
			vehicleContent: '',
			CHECKID: '',
			xhdzObjItem: {},
			// mapKey: '3NYBZ-WRL3Z-V3VXL-ZYUPM-SSP6J-S2BBJ' ,// 你的腾讯地图key
		}
	},
	onLoad(op) {
		console.log(op)
		if (op.ID) {
			this.CHECKID = op.ID
		}
	},
	onShow() {
		uni.removeStorageSync('id')
		this.vehicleList();
	},
	onReachBottom() {
		if (this.page == this.countpage) {
			return this.status = "nomore"
		}
		this.page++
		this.vehicleList()
	},
	methods: {
		getopsxinxi(item) {
			console.log(item)
			checkOpenGPSServiceByAndroid()
			const latitude = item.ORMTB404CA07;
			const longitude = item.ORMTB404CA06;
			let txMapUrl =`https://apis.map.qq.com/tools/poimarker?type=0&marker=coord:${latitude},${longitude};title:${item.ORMTB404CA00};addr:${item.ORMTB404CA05}&key=${this.mapKey}&referer=myapp`;
			
			uni.navigateTo({
				url: `/pages/webmap/index?mapurl=${encodeURIComponent(txMapUrl)}`
			
			});
			// uni.getLocation({
			// 	type: 'gcj02', //返回可以用于uni.openLocation的经纬度
			// 	success: function (res) {
			// 		console.log(res)
			// 		const latitude = item.ORMTB404CA07;
			// 		const longitude = item.ORMTB404CA06;
			// 		uni.openLocation({
			// 			latitude: latitude,
			// 			longitude: longitude,
			// 			scale: 10,
			// 			name: item.ORMTB404CA00,
			// 			address: item.ORMTB404CA05,
			// 			success: function () {
			// 				console.log('success');
			// 			}
			// 		});
			// 	}
			// });
		},
		
		xhdxzFun(item) {
			console.log(item)
			uni.$emit('handClickSelectAddress', item)
			uni.navigateBack({
				url: '/pages/msgFb/index'
			});
		},
		// 删除
		vehicleConfirm() {
			uni.request({
				url: this.baseUrl + '/orm/ormtb404/delete',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB404ID: this.vehicleid,
					sign: this.userinfo.sign,
				},
				success: (res) => {
					// console.log(res);
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '删除成功',
							type: 'default',
							icon: false
						})
						if (this.vehicleid == this.CHECKID) {
							this.CHECKID = ''
						}
						this.vehicleid = ''
						this.page = 1
						this.countpage = 1
						this.vehicleList();
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.showToast({
						title: res.data.message,
						duration: 5000,
						icon: 'none',
					});
				}
			});
		},
		prohibit(item) {
			this.vehicleLoginShow = true
			this.vehicleid = item.ORMTB404ID
			this.vehicleContent = '您确定要删除配送地：' + item.ORMTB404CA00 + '吗？'
		},
		modify(item) {
			uni.navigateTo({
				url: '../deliveryPlaceModify/index?item=' + JSON.stringify(item)
			})
		},
		addDeliverySite(item) {
			uni.setStorageSync('id', item.ORMTB404ID);
			uni.setStorageSync('freightDP', item.ORMTB404CA01);
			uni.navigateTo({
				url: '../deliverySite/index'
			})
		},
		//添加
		addCar() {
			uni.navigateTo({
				url: '../deliveryPlaceAdd/index'
			})
		},
		vehicleList() {
			uni.showLoading({
				title: '请求中...',
				mask: true
			});
			this.status = "loading"
			if (this.userinfo.sign == 'CUS-1') {
				var ORMTB400ID = this.userinfo.ORMTB400ID
			} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
				var ORMTB400ID = this.userinfo.ORMTB410ID
			}
			uni.request({
				url: this.baseUrl + '/orm/ormtb404/selectPageList',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB400ID: ORMTB400ID,
					sign: this.userinfo.sign,
					CHECKID: this.CHECKID,
					page: this.page,
					limit: 10,
				},
				success: (res) => {
					uni.hideLoading();
					console.log(res);
					if (res.data.code == 200) {
						if (!res.data.data || res.data.data == null) {
							this.vehicleArrList = []
							this.page = 1
							this.countpage = 1
							return
						}
						var data = res.data.data || []
						if (this.page > 1) {
							this.vehicleArrList = [...this.vehicleArrList, ...data]
						} else {
							this.vehicleArrList = data
						}
						this.countpage = Math.ceil(res.data.count / 10)
					} else {
						this.vehicleArrList = []
						this.page = 1
						this.countpage = 1
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
					if (this.countpage == this.page) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
				},
				fail: (res) => {
					if (this.countpage == this.page) {
						this.status = "nomore"
					} else {
						this.status = "loadmore"
					}
					uni.hideLoading();
					uni.showToast({
						title: res.data.message,
						duration: 5000,
						icon: 'none',
					});
				}
			});
		},
	}
}
</script>

<style scoped>
.sendorder-loadmore {
	padding: 20rpx 0 20rpx 0;
}

.vehicle .zanWSJ {
	padding-top: 200rpx;
}

.vehicle .zanWSJ>image {
	display: block;
	margin: 0 auto;
	height: 360rpx;
	width: 43%;
}


.vehicle {
	width: 100%;
	min-height: 135vh;
	background-color: rgba(242, 242, 242, 1);
	overflow: hidden;
}

/* 列表 */

.vehicle .vehicle-car {
	width: 100%;
	background: rgba(255, 255, 255, 1);
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: space-between;
	padding: 24rpx;
}

.vehicle .vehicle-car-zdy {
	/* width: 100%; */
	/* background: rgba(255, 255, 255, 1); */
	padding: 24rpx;
}

.vehicle .vehicle-car-box {
	display: flex;
	flex-direction: row;
	align-items: center;
}

.vehicle .vehicle-stick {
	width: 6rpx;
	height: 29rpx;
	display: inline-block;
	background: linear-gradient(0deg, rgba(57, 163, 216, 1), rgba(35, 199, 217, 1));
	border-radius: 8px;
	margin-right: 16rpx;
	line-height: 29rpx;
	position: relative;
	top: 2rpx;
}

.vehicle .vehicle-car-details {
	/* font-size: 28rpx; */
	color: rgba(51, 51, 51, 1);
	/* height: 29rpx; */
	line-height: 40rpx;
	/* height: 0.37rem;
	  line-height: 0.37rem; */
}

.vehicle .xxadres {
	font-size: 28rpx;
	color: #666;
	padding-bottom: 20rpx;
	display: flex;
	line-height: 35rpx;
}

.vehicle .adresTit {
	display: flex;
}

/* 添加 */
.vehicle-add {
	height: 60rpx;
	/* font-size: 28rpx; */
	color: rgba(255, 254, 254, 1);
	background: rgba(0, 160, 241, 1);
	display: flex;
	flex-direction: row;
	align-items: center;
	border-radius: 10rpx;
	padding: 10rpx;
}

.vehicle .icontianjia,
.vehicle .iconxiugai,
.vehicle .iconbaocun,
.vehicle .iconshanchu,
.vehicle .iconqiyong,
.vehicle .iconchakan {
	font-size: 30rpx;
	padding-left: 10rpx;
}

.vehicle-add-button {
	padding: 0 10rpx;
}

/* 内容 */
.vehicle-content-box {
	/* width: 100%; */
	/* background: rgba(255, 255, 255, 1); */
}

.vehicle .vehicle-content {
	/* margin-top: 8rpx; */
	border-bottom: 2rpx solid rgba(230, 230, 230, 1);
}

.vehicle .vehicle-carNumber {
	font-size: 36rpx !important;
	font-weight: bold;
	padding-bottom: 20rpx;
	line-height: 40rpx;
}

.vehicle .vehicle-bottom view:nth-child(3)>view:first-child text:first-child {}

.vehicle .vehicle-button-box {
	display: flex;
	justify-content: flex-end;
	padding: 30rpx 0;
}

.vehicle-button-margin {
	margin-right: 20rpx;
}

.vehicle-content-bottom {
	padding: 0 24rpx;
}

.vehicle-carName-phone {
	border-bottom: 2rpx solid rgba(230, 230, 230, 1);
	display: flex;
	justify-content: space-between;
	padding: 18rpx 0;
}

.vehicle input {
	display: inline-block;
	margin-bottom: 0 !important;
	padding: 0 !important;
	height: 43rpx !important;
	margin-left: 7rpx;
	color: rgba(51, 51, 51, 1);
	font-size: 34rpx;
	text-align: center;
	border: 2rpx solid rgba(0, 0, 0, .2);
	border-radius: 6rpx;
}

.inputBorder {
	border: none !important;
	text-align: left !important;
}

.deliveryPlace-carName {
	width: 100%;
}

.vehicle-input-money {
	width: 80% !important;
	display: inline-block;
	text-align: right;
}

.vehicle-input-two {
	width: 190rpx !important;
}

.vehicle-phone {
	width: 142rpx;
	display: inline-block;
	font-size: 34rpx;
	color: rgba(153, 153, 153, 1);
}

.vehicle-tare {
	padding: 18rpx 0;
}

.vehicle-dun {
	color: rgba(51, 51, 51, 1);
	font-size: 34rpx;
}

/* 收货地新style */
.xjshd {
	position: fixed;
	z-index: 999;
	bottom: 0;
	text-align: center;
	width: 100%;
	/* height: 44rpx;
		font-size: 28rpx; */
	color: rgba(255, 254, 254, 1);
	/* display: flex;
		flex-direction: row;
		align-items: center; */
	background: #fff;
	padding: 30rpx 40rpx;
}

.shdList {
	border-radius: 20rpx;
	background: #fff;
	margin: 20rpx;
}

.xzxhdz {
	background: #FF0000;
	color: #fff;
	font-size: 24rpx;
	/* padding: 2px; */
	margin-right: 10rpx;
	border-radius: 40rpx;
	width: 40rpx;
	height: 40rpx;
	display: inline-block;
	text-align: center;
}
</style>
